<template>
  <view>
    
    <view class="">
		<view class="relode" @click="reloade">
			<uni-icons type="reload" class="reload" size="25"></uni-icons>
		</view>
		
		
      <!-- 循环每学年的课程 -->
      <uni-card title="个人成绩" note="Tips">
            <view class="list-item" v-for="(item,index) in curData" :key="index">
                  <view class="item-cj cj">
                  	 <text class="list-item-title">{{item.yjkcmc}}</text>
					 <text class="list-item-title">{{item.jdVal}}</text>
                  </view>
				  <view class="">
				  	<text>教师：{{item.teacherXms.replace(/[\[(\],)]/g,'')}}</text>
				  </view>
				  <view class="item-cj">
				  	<text class="rightText">平时：{{item.pscj}}</text>
				  	<text class="rightText">期末：{{item.qmcj}}</text>
					<text class="rightText">总成绩：{{item.zpcj}}</text>
				  </view>
                 
            </view>
      </uni-card>
    </view>
  </view>
</template>

<script>
  import {
    encrypt
  } from '@/utils/encryp.js'
  import getScore from "@/u_api/getScore.js"
  export default {
    data() {
      return {
        jwtcode: "",
        // 所有课程信息
        scoreData: [],
		curData:[],
        name: "",
        // 用户信息
        userData: {
          id: '',
          jwloginToken: ''
        },
        // 开课学年
        year:["2018","2019","2020","2021","2022"],
		average:0
      } 
    },
    onLoad() {
	  uni.intercept();
      this.getData();

    },
	onReachBottom(){
		this.pushCur()
	},
    methods: {
      async getData() {
			
			let score = uni.getStorageSync('score');
			if(score) {
				this.scoreData = score;
			}else{
				this.scoreData = await getScore.getScoreInfo();
				uni.setStorageSync('score',this.scoreData);
			}
		    this.scoreData.sort((a,b)=>b.jdVal - a.jdVal);
			this.pushCur();
        	
      },
	  pushCur(){
	      let i = 15;
		  while(i-- && this.scoreData.length > 0){
			  this.curData.push(this.scoreData.shift());
			  
		  }  
	  },
	  reloade(){
		  uni.removeStorageSync('score');
		  this.curData = [];
		  this.getData();
	  }
    }
  }
</script>

<style>
  .nav {
    display: flex;
    justify-content: space-between;
  }

  .credit-totle {
    margin-top: 20rpx;
  }

.list-item{
  padding-bottom: 20rpx;
 
 
  margin-top: 20rpx;
  color: #aaa;
  display: flex;
  flex-direction: column;
  justify-content: space-between; 
}

.relode{
	position: absolute;
	z-index: 2;
	right: 10%;
	top:10px;
}
.average{
	position: absolute;
	z-index: 2;
	right: 25%;
	top:25rpx;
	font-size: 30rpx;
}
.item-cj{
	display: flex;
	justify-content:space-between;
}
.cj{
	color: #3c3c3c;
}
</style>